using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using Gencode.PrsCommon.App;
using Gencode.Common.SQL;

namespace Personalplaner
{
    class DDiversGenerator
    {
        List<IPersonRow> row = new List<IPersonRow>();
		string von;
		string bis;

        public DDiversGenerator(int prsID, string von, string bis)
        {
			this.von = von;
			this.bis = bis;

            addRow(prsID);
        }

        private void addRow(int prsID)
        {
            PDiversRow divRow = null;

            DataView dv = getRowDV(prsID);
            if (dv.Count > 0)
            {
                while (dv.Count > 0)
                {
                    divRow = new PDiversRow();
                    divRow.PlanName = dv[0].Row[2].ToString();
                    divRow.Datum = DateUtil.ConvertSqlToDate(dv[0].Row[3].ToString());
                    divRow.Stunden = dv[0].Row[4].ToString();
                    divRow.Grund = dv[0].Row[5].ToString();
                    divRow.SetData();

                    row.Add(divRow);
                    dv.Delete(0);
                }
            }
        }

        private DataView getRowDV(int prsID)
        {
			Querry stp = new Querry();
            stp.SetSTPName("get_persondiversrow");
            stp.AddParameter("@prsid", prsID);
			stp.AddParameter("@von", DateUtil.ConvertDateToSQL(von));
			stp.AddParameter("@bis", DateUtil.ConvertDateToSQL(bis));
            stp.AddParameter("@jahr", Verwaltung.Year);

			return stp.ExecuteForDataView();
        }

        internal List<IPersonRow> Row
        {
            get { return row; }
        }
    }
}
